//
//  BSMyInfoViewController.m
//  SuoSiApp
//
//  Created by zhang on 16/4/9.
//  Copyright © 2016年 Ym. All rights reserved.
//

#import "BSUIUserInfoBase+category.h"
#import "BSUIUserInfoBase.h"
#import "BSMyInfoView.h"
#import "BSMyInfoViewController.h"

@interface BSMyInfoViewController ()<UITextFieldDelegate>

@property (nonatomic, strong) BSMyInfoView *myInfoView;

// 个人信息的model;
@property (nonatomic, strong) BSUIUserInfoBase *userBaseinfoModel;

@end

@implementation BSMyInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    self.view.backgroundColor = [UIColor colorWithRed:214.0/255 green:214.0/255 blue:214.0/255 alpha:1];
    self.myInfoView = [[BSMyInfoView alloc]initWithFrame:CGRectMake(0, 00, kScreenWidth, kScrenHeight)];
    
    self.myInfoView.scrollView.bounces = YES;
    [self.myInfoView.backBT addTarget:self action:@selector(backBT) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.myInfoView.saveBT addTarget:self action:@selector(saveMyinfomation) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    [self.view addSubview:_myInfoView];
    
    //    进来之前 先请求数据
    [self getInformation];

    
    
}
#pragma mark  提交我的信息
- (void)saveMyinfomation{

    NSString *idcard = self.myInfoView.IDCardTF.text;
     NSNumber *height = [NSNumber numberWithFloat:[ self.myInfoView.heightTF.text floatValue]];
    NSNumber *weight = [NSNumber numberWithFloat:[ self.myInfoView.weightTF.text floatValue]];
     NSString *zipCode = self.myInfoView.postCodeTF.text;
     NSString *realName = self.myInfoView.nameTF.text;
     NSString *remaks = self.myInfoView.remarkTF.text;
     NSString *addrr = self.myInfoView.addressTF.text;
     NSString *moblieNum = self.myInfoView.phoneTF.text;
    
    CGFloat Fheight = [height floatValue];
    CGFloat Fweight = [weight floatValue];
    if (Fheight < 100 || Fheight > 250) {
        [PKRequestManager showAlertView:@"身高范围限制在100cm - 250cm"];
        return;
    }
    
    if (Fweight < 30 || Fweight > 200) {
        [PKRequestManager showAlertView:@"体重范围限制在30kg - 200kg"];
        return;
    }
    
    NSLog(@"提交我的信息");
    [PKRequestManager UpdateUserBaseWithnetUrl:NetStr userID:self.user_id iDCard:idcard height:height weight:weight zipCode:zipCode realName:realName remark:remaks fullAddr:addrr moblieNum:moblieNum method:POST finish:^(NSData *data) {
        
        [BSUserSGton userHandle].verifiPhoneNum = moblieNum;
        [self.navigationController popViewControllerAnimated:YES];
    } error:^(NSError *error) {
        ;
    }];

}

- (void)getInformation{

    [PKRequestManager GetUserBaseWithnetUrl:NetStr userID:self.user_id method:POST finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        //    根据收到的data  给自己的属性 赋值
        
     //   NSLog(@"%@",dic);
        NSDictionary *dataDic = [NSDictionary dictionaryWithDictionary:dic[@"Data"]];
        _userBaseinfoModel = [[BSUIUserInfoBase alloc]init];
        [_userBaseinfoModel setValuesForKeysWithDictionary:dataDic];
        self.myInfoView.infoBaseModel = _userBaseinfoModel;

        
//        [_userBaseinfoModel dealWithData:data];
        
    } error:^(NSError *error) {
        ;
    }];


}

- (void)viewWillAppear:(BOOL)animated{
    self.myInfoView.phoneTF.text = [BSUserSGton userHandle].verifiPhoneNum ;
}

- (void)viewDidAppear:(BOOL)animated{

}

- (void)backBT{

    [self.navigationController popViewControllerAnimated:YES];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
